﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace YuzKitabi.Data
{
    class PersonXmlDataProvider:IDataProvider
    {
        private List<Person> personList;
        public object GetData()
        {
            return GetPerson();
        }

        private XmlDocument ReadXml()
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(@"C:\Users\Oğuz\Desktop\Yeni klasör\yuzkitabi\Presentation\WebApplication.UI\Person.xml");
                return doc;
            }
            catch (Exception ex)
            {
                return null;
            }
        }



        private List<Person> GetPerson()
        {
            XmlDocument doc = ReadXml();
            XmlNodeList list = doc.SelectNodes("Persons/Person");

            if (list != null)
            {
                personList = new List<Person>();

                foreach (XmlNode item in list)
                {
                    Person person = new Person();
                    person.ID = item.Attributes["ID"].Value;
                    person.Name = item.Attributes["Name"].Value;
                    person.Years = item.Attributes["Years"].Value;

                    personList.Add(person);
                }
                return personList;
            }

            return null; 


        }
    }
}
